/*
MIT License

Copyright (c) 2022 chen-chaochen@Easylosu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.

*/

#include<iostream>
#include<ctime>
#include<thread>
#include "libtime.hpp"
using namespace std;
extern "C"{
    LNI losu_time_datestr(){
        char s[1024];
        losu_time_rt[0] = '\0';
        time_t _t_ptr;
		struct tm *_t ;
		time(&_t_ptr);
		_t = localtime(&_t_ptr);
		sprintf(losu_time_rt,"%d",_t -> tm_year +1900);
        sprintf(s,"%d年%d月%d日 %s",_t -> tm_year +1900,_t -> tm_mon+1,_t -> tm_mday,losu_time_dateweek());
        sprintf(losu_time_rt,"%s",s);
        return losu_time_rt;
    }
    LNI losu_time_dateyear(){
        losu_time_rt[0] = '\0';
        time_t _t_ptr;
		struct tm *_t ;
		time(&_t_ptr);
		_t = localtime(&_t_ptr);
		sprintf(losu_time_rt,"%d",_t -> tm_year +1900);
        return losu_time_rt;
    }
    LNI losu_time_datemon(){
        losu_time_rt[0] = '\0';
        time_t _t_ptr;
		time(&_t_ptr);
		sprintf(losu_time_rt,"%d",localtime(&_t_ptr) -> tm_mon+1);
        return losu_time_rt;
    }
    LNI losu_time_dateday(){
        losu_time_rt[0] = '\0';
        time_t _t_ptr;
		time(&_t_ptr);
		sprintf(losu_time_rt,"%d",localtime(&_t_ptr) -> tm_mday);
        return losu_time_rt;
    }
    LNI losu_time_dateweek(){
        losu_time_rt[0] = '\0';
        time_t _t_ptr;
		time(&_t_ptr);
        switch(localtime(&_t_ptr) -> tm_wday){
            case 1: sprintf(losu_time_rt,"周一");break;
            case 2: sprintf(losu_time_rt,"周二");break;
            case 3: sprintf(losu_time_rt,"周三");break;
            case 4: sprintf(losu_time_rt,"周四");break;
            case 5: sprintf(losu_time_rt,"周五");break;
            case 6: sprintf(losu_time_rt,"周六");break;
            case 7: sprintf(losu_time_rt,"周日");break;
        }
        return losu_time_rt;
    }
    LNI losu_time_timestr(){
        losu_time_rt[0] = '\0';
        time_t _t_ptr;
		time(&_t_ptr);
		sprintf(losu_time_rt,"%d时%d分%d秒",localtime(&_t_ptr) -> tm_hour,localtime(&_t_ptr) -> tm_min,localtime(&_t_ptr) -> tm_sec);
        return losu_time_rt;
    }
    LNI losu_time_timehour(){
        losu_time_rt[0] = '\0';
        time_t _t_ptr;
		time(&_t_ptr);
		sprintf(losu_time_rt,"%d",localtime(&_t_ptr) -> tm_hour);
        return losu_time_rt;
    }
    LNI losu_time_timemin(){
        losu_time_rt[0] = '\0';
        time_t _t_ptr;
		time(&_t_ptr);
		sprintf(losu_time_rt,"%d",localtime(&_t_ptr) -> tm_min);
        return losu_time_rt;
    }
    LNI losu_time_timesec(){
        losu_time_rt[0] = '\0';
        time_t _t_ptr;
		time(&_t_ptr);
		sprintf(losu_time_rt,"%d",localtime(&_t_ptr) -> tm_sec);
        return losu_time_rt;
    }
    LNI losu_time_timeclock(){
        losu_time_rt[0] = '\0';
		sprintf(losu_time_rt,"%ld",clock());
        return losu_time_rt;
    }
    LNI losu_time_sleep(LNI tm,LNI ms){
        string _ms = ms;
        if(_ms=="秒")
            std::this_thread::sleep_for(std::chrono::seconds(atoi(tm)));
        else
            std::this_thread::sleep_for(std::chrono::milliseconds(atoi(tm)));
        return (char*)('\0');
    }
}